<template>
  <div class="menu">
    <div class="one">
      <ul>
        <li v-for="(item, index) in type" :key="index" ref="li" @click="fill(index)">
          <img
            :src="`https://fuss10.elemecdn.com/${item.image_url.charAt(0)}/${item.image_url.substr(1,2)}/${item.image_url.substr(3)}.${item.image_url.substr(item.image_url.length-4)=='jpeg'?'jpeg':item.image_url.substr(item.image_url.length-3)}`"
            alt
          />
          <span>{{item.name}}</span>
          <a href @click.prevent class="mui-icon mui-icon-arrowright"></a>
        </li>
      </ul>
    </div>
    <div class="two">
      <ul>
        <li
          v-for="(item, index) in right_list"
          :key="index"
          @click="search(item.id,item.name) "
          ref="ri"
        >
          <span>{{item.name}}</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  props: ['type', 'params', 'num'],
  data() {
    return {
      right_list: []
    }
  },
  methods: {
    fill(index) {
      this.$emit('addnum', index)
      this.$refs['li'].forEach((item, i) => {
        if (i == index) {
          item.style.backgroundColor = 'white'
        } else {
          item.style.backgroundColor = ''
        }
      })
      this.right_list = this.type[index].sub_categories
    },
    rightFill() {
      this.right_list.forEach(({ id }, i) => {
        if (id == this.params.restaurant_category_ids[0]) {
          this.$refs['ri'][i].style.color = 'red'
        } else this.$refs['ri'][i].style.color = ''
      })
    },
    search(id, head) {
      this.$emit('addhead', head)
      window.console.log(id)
      this.$emit('getList', {
        restaurant_category_id: [],
        restaurant_category_ids: [id],
        New: true
      })
      this.$emit('Appear', 'typeMenu')
      this.$emit('off', 'typeMenu')
    }
  },
  mounted() {
    this.fill(this.num)
  },
  updated() {
    //right.left中的dom时动态渲染的,所以操作这里的dom必须在updated中执行
    this.rightFill()
  }
}
</script>
<style  scoped>
* {
  margin: 0;
  padding: 0;
}
.menu {
  display: flex;
  background-color: white;
  height: 18rem;
}
.menu > div {
  flex: 1;
}
li {
  padding: 0 1rem;
  display: flex;
  height: 2rem;
  align-items: center;
}
.one li {
  background-color: #f5f5f5;
}
li > img {
  width: 1rem;
  height: 1rem;
  margin-right: 0.5rem;
}
.one li > span {
  font-size: 0.7rem;
  flex: 2;
}
li > a {
  font-size: 1rem;
  float: right;
  color: black;
}
.two {
  height: 100%;
  overflow: scroll;
}
.two ul {
  padding-left: 1rem;
}
.two li {
  justify-content: space-between;
  background-color: white;
  border-bottom: 1px solid #f5f5f5;
  padding-left: 0;
}
.two li > span {
  font-size: 0.7rem;
}
.two li:first-child {
  display: none;
}
</style>